package com.xxjqr.rbac.response;


import com.xxjqr.rbac.enums.CodeMsgEnum;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class Response<T> {
    private Object code;
    private String msg;
    private LocalDateTime timestamp = LocalDateTime.now();
    private T data;

    //@SuppressWarnings("rawtypes")
    public static Response<Void> fail(Object code, String msg) {
        Response<Void> objectResponse = new Response<>();
        objectResponse.setCode(code);
        objectResponse.setMsg(msg);
        objectResponse.setData(null);
        return objectResponse;
    }

    //右边的<T>表示用Response去定义变量的时候，一定要指定一个具体的类型；因为Response有一个T类型的属性
    //左边的<T>表示参数参数可以使用T泛型
    public static <T>Response<T> success(T data) {
        Response<T> response = new Response<>();
        response.setMsg(CodeMsgEnum.SUCESS.getMsg());
        response.setCode(CodeMsgEnum.SUCESS.getCode());
        response.setData(data);
        return response;
    }
}
